<template>
  <el-row>
    <el-col :offset="2" :span="20">
      <zFrom
        ref="zfrom"
        :chargecfg="ChargeCfg"
        label-width="140px"
        :nowdata="formdata"
        :nowinputs="frominputs"
      >
        <template #gtel="scope">
          <el-form-item
            :label="scope.item.label"
            :prop="scope.item.value"
            status-icon
          >
            <el-input
              v-model="scope.formdata[scope.item.value]"
              @blur="gtelblurfn"
            />
          </el-form-item>
        </template>
      </zFrom>
      <div
        ref="vueqrcode"
        style="position: fixed; bottom: -1000000px; right: 0; color: #000"
      >
        <vue-qrcode
          :gls="qrcodedata.gls"
          :glsi="qrcodedata.glsi"
          :gtel="qrcodedata.gtel"
        />
      </div>
      <div
        ref="refzjsbarcode"
        style="position: fixed; bottom: -10000px; left: 0"
      >
        <zjsbarcode :gtels="zjsbarcodegtels" />
      </div>
      <exceladd ref="exceladd" @save="excelsave" />
      <div style="text-align: right">
        <el-button v-if="user.utype == 3" type="primary" @click="csdataalookfn">
          搜索结果
        </el-button>
        <el-button v-if="user.utype == 3" type="primary" @click="excelfn">
          Excel导入
        </el-button>
        <el-button v-if="user.utype == 3" type="primary" @click="gteljc">
          桩号检测
        </el-button>

        <el-button type="primary" @click="txmfn">生成条形码</el-button>
        <el-button :loading="ewmloading" type="primary" @click="qrfn">
          生成二维码
        </el-button>

        <el-button type="primary" @click="ChargeSetaddfn">确认执行</el-button>
      </div>
    </el-col>
  </el-row>
</template>
<script>
  import { h } from 'vue'
  import zFrom from '../zFrom/zFrom'
  import { parfn } from '../../utils/requestpar'
  import vueQrcode from '@/mixins/QRCode'
  import zjsbarcode from '@/mixins/jsbarcode'
  import exceladd from './exceladd.vue'
  export default {
    // mixins:[QRCode],
    name: 'ChargesetaddFrom',
    components: {
      zFrom,
      vueQrcode,
      zjsbarcode,
      exceladd,
    },
    props: {
      gtel: {
        default: '',
      },
      chargecardata: {
        default: {},
      },
    },
    data() {
      let qcgtypes = ['2', '10']
      return {
        ewmloading: false,
        user: this.$store.state.user.USearch,
        ChargeCfg: {},
        formdata: {},
        // frominputs:[],
        ChargeSetaddjson: [
          {
            name: '桩号',
            zd: 'gtel',
            rule: [{ required: true, message: '请输入桩号', trigger: 'blur' }],
          },
          {
            name: '设置类型',
            zd: 'lx',
            type: 'select',
            rule: [{ required: true, message: '请选择', trigger: 'blur' }],
            options: [
              {
                name: '开始充电',
                value: '1',
                gets: [
                  {
                    name: '通道',
                    zd: 'xt',
                    rule: [
                      {
                        required: true,
                        message: '请输入通道号',
                        trigger: 'blur',
                      },
                    ],
                  },
                ],
              },
              {
                name: '结束充电',
                value: '2',
                gets: [
                  {
                    name: '通道',
                    zd: 'xt',
                    rule: [
                      {
                        required: true,
                        message: '请输入通道号',
                        trigger: 'blur',
                      },
                    ],
                  },
                ],
              },
              {
                name: '等待时间',
                value: '3',
                gets: [
                  {
                    name: '等待时间',
                    zd: 'xt',
                    dw: '分钟',
                    defaultValue: '5',
                    rule: [
                      {
                        required: true,
                        message: '请输入分钟',
                        trigger: 'blur',
                      },
                    ],
                  },
                ],
              },
              {
                name: '远程开锁',
                value: '4',
              },
              {
                name: '心跳周期',
                value: '5',
                gets: [
                  {
                    name: '心跳周期',
                    zd: 'xt',
                    dw: '秒',
                    defaultValue: '60',
                    rule: [
                      {
                        required: true,
                        message: '请输入心跳周期',
                        trigger: 'blur',
                      },
                    ],
                  },
                ],
              },
              {
                name: '修改设备ID',
                value: '6',
                gets: [
                  {
                    name: '设备桩号',
                    zd: 'newgtel',
                    rule: [
                      {
                        required: true,
                        message: '请输入设备桩号',
                        trigger: 'blur',
                      },
                    ],
                  },
                  { name: '验证码', zd: 'yzm', type: 'utel' },
                ],
              },
              {
                name: '设置设备IP和端口',
                value: '7',
                gets: [
                  {
                    name: '服务器IP',
                    zd: 'ip',
                    bindingzd: { attr: 'chargecfg', zd: 'ip' },
                  },
                  {
                    name: '服务器端口',
                    zd: 'port',
                    bindingzd: { attr: 'chargecfg', zd: 'port' },
                  },
                ],
              },
              {
                name: '设备远程升级',
                value: '8',
                gets: [
                  {
                    name: '升级类型',
                    zd: 'xt',
                    placeholder: '1.主板升级2.底板升级',
                    rule: [
                      {
                        required: true,
                        message: '请输入升级类型',
                        trigger: 'blur',
                      },
                    ],
                  },
                ],
              },
              {
                name: '涓流时间',
                value: '30',
                gets: [
                  {
                    name: '涓流时间',
                    zd: 'xt',
                    placeholder: '请输入时间（分钟）',
                    defaultValue: '60',
                    dw: '分钟',
                    bindingzd: { attr: 'chargecfg', zd: 'jlsj' },
                  },
                ],
                if: () => {
                  return !this.ifqcrjbb23()
                },
              },
              {
                name: '汽车桩占空比',
                value: '30',
                gets: [
                  {
                    name: '占空比',
                    zd: 'xt',
                    defaultValue: '50',
                    bindingzd: { attr: 'chargecfg', zd: 'jlsj' },
                    rule: [
                      {
                        type: 'string',
                        required: true,

                        validator: (rule, value, callback) => {
                          value = Number(value)
                          if (value >= 27 && value <= 53) {
                            callback()
                          } else {
                            callback(`占空比应在27到53之间`)
                          }
                        },
                      },
                    ],
                  },
                ],
                if: () => {
                  return this.ifqcrjbb23()
                },
              },
              {
                name: '设置电流最大值',
                value: '11',
                gets: [
                  {
                    name: '电流最大值',
                    zd: 'xt',
                    placeholder: '请输入（以A为单位）',
                    dw: 'A',
                    fl: 10,
                    defaultValue: '4',
                    bindingzd: { attr: 'chargecfg', zd: 'maxdl' },
                  },
                ],
                if: () => {
                  return !this.ifqcrjbb23()
                },
              },
              {
                name: '汽车CP方式切换次数',
                value: '11',
                gets: [
                  {
                    name: '切换次数',
                    zd: 'xt',
                    defaultValue: '3',
                    bindingzd: { attr: 'chargecfg', zd: 'maxdl' },
                    rule: [
                      {
                        type: 'string',
                        required: true,

                        validator: (rule, value, callback) => {
                          value = Number(value)
                          if (value >= 3 && value <= 100) {
                            callback()
                          } else {
                            callback(`切换次数应在3到100之间`)
                          }
                        },
                      },
                    ],
                  },
                ],
                if: () => {
                  return this.ifqcrjbb23()
                },
              },
              {
                name: '重启设备',
                value: '12',
              },
              {
                name: '设置设备音量',
                value: '27',
                gets: [
                  {
                    name: '音量大小',
                    zd: 'xt',
                    defaultValue: '1',
                    bindingzd: { attr: 'chargecfg', zd: 'b_yy' },
                    rule: [
                      {
                        pattern: /^([0-9]|1[0-5])$/,
                        message: '音量大小：0-15',
                      },
                    ],
                  },
                ],
              },
              {
                name: '关闭人体语音播报',
                value: '15',
              },
              {
                name: '打开烟雾报警检测',
                value: '16',
              },
              {
                name: '关闭烟雾报警检测',
                value: '17',
              },
              {
                name: '打开硬件过流检测',
                value: '18',
              },
              {
                name: '关闭硬件过流检测',
                value: '19',
              },
              {
                name: '打开插拔检测功能',
                value: '20',
              },
              {
                name: '关闭插拔检测功能',
                value: '21',
              },
              {
                name: '投币箱1元充电时间设置和是否启用',
                value: '23',
                gets: [
                  {
                    name: '是否使用',
                    zd: 'port',
                    type: 'select',
                    options: [
                      {
                        name: '否',
                        value: '0',
                      },
                      {
                        name: '是',
                        value: '1',
                      },
                    ],
                    defaultValue: '0',
                    bindingzd: { attr: 'chargecfg', zd: 'b_tb' },
                  },
                  {
                    name: '充电时间',
                    zd: 'xt',
                    placeholder: '请输入时间（分）',
                    bindingzd: { attr: 'chargecfg', zd: 'tbsj' },
                  },
                ],
              },
              {
                name: '开始充电（不自动关闭的充电）',
                value: '25',
              },
              {
                name: '设置断开检测次数',
                value: '26',
                gets: [
                  {
                    name: '断电检查次数',
                    zd: 'xt',
                    placeholder: '请输入（次）',
                    defaultValue: '5',
                    bindingzd: { attr: 'chargecfg', zd: 'ddjcc' },
                  },
                ],
              },
              {
                name: '设备温度报警值',
                value: '31',
                if: 'gtype',
                nozhi: qcgtypes,
                gets: [
                  {
                    name: '报警值',
                    zd: 'xt',
                    defaultValue: '0',
                    zzstr: '报警值最大值为254',
                    bindingzd: { attr: 'chargecfg', zd: 'wdsbal' },
                    rule: [
                      {
                        pattern: /^([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-6])$/,
                        message: '请输入(最大值为256)',
                      },
                    ],
                  },
                ],
              },
              {
                name: '风扇最高温度',
                value: '31',
                if: 'gtype',
                zhi: qcgtypes,
                gets: [{ name: '温度阈值', zd: 'xt', dw: '度' }],
              },
              {
                name: '电缆温度报警值',
                value: '32',
                if: 'gtype',
                nozhi: qcgtypes,
                gets: [
                  {
                    name: '报警值',
                    zd: 'xt',
                    defaultValue: '0',
                    bindingzd: { attr: 'chargecfg', zd: 'wdxlal' },
                    rule: [
                      {
                        pattern: /^([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-6])$/,
                        message: '请输入(最大值为256)',
                      },
                    ],
                  },
                ],
              },
              {
                name: '风扇最低温度',
                value: '32',
                if: 'gtype',
                zhi: qcgtypes,
                gets: [{ name: '最低温度阈值', zd: 'xt', dw: '度' }],
              },
              {
                name: '设置涓流电流值',
                value: '33',
                gets: [
                  {
                    name: '涓流电流值',
                    zd: 'xt',
                    placeholder: '涓流电流值(以10毫安为单位)',
                    defaultValue: '',
                    bindingzd: { attr: 'chargecfg', zd: 'jldl' },
                  },
                ],
              },
              {
                name: '设置断开电流值',
                value: '34',
                gets: [
                  {
                    name: '断开电流值',
                    defaultValue: '20',
                    zd: 'xt',
                    placeholder: '断开电流值(以毫安为单位，最大值255)',
                    bindingzd: { attr: 'chargecfg', zd: 'dkdl' },
                  },
                ],
              },
              {
                name: '开面板灯',
                value: '36',
              },
              {
                name: '关面板灯',
                value: '37',
              },
              {
                name: '打开插拔断电',
                value: '38',
                if: 'gtype',
                nozhi: qcgtypes,
              },
              {
                name: '关闭插拔断电',
                value: '39',
                if: 'gtype',
                nozhi: qcgtypes,
              },
              {
                name: '打开防倾倒',
                value: '38',
                if: 'gtype',
                zhi: qcgtypes,
              },
              {
                name: '关闭防倾倒',
                value: '39',
                if: 'gtype',
                zhi: qcgtypes,
              },
              {
                name: '触摸副板远程升级',
                value: '41',
              },
              {
                name: '打开软件过流检测',
                value: '43',
              },
              {
                name: '关闭软件过流检测',
                value: '44',
              },
              {
                name: '打开第二报警服务器',
                value: '46',
              },
              {
                name: '关闭第二报警服务器',
                value: '47',
              },
              {
                name: '远程读表',
                value: '48',
              },
              {
                name: '查询系统参数',
                value: '52',
              },
              {
                name: '打开充满自停',
                value: '55',
                if: 'gtype',
                nozhi: qcgtypes,
              },
              {
                name: '关闭充满自停',
                value: '56',
                if: 'gtype',
                nozhi: qcgtypes,
              },
              {
                name: '打开设备指示灯',
                value: '55',
                if: 'gtype',
                zhi: qcgtypes,
              },
              {
                name: '关闭设备指示灯',
                value: '56',
                if: 'gtype',
                zhi: qcgtypes,
              },
              {
                name: '读取SIM卡号',
                value: '61',
              },
              {
                name: '开启温度报警',
                value: '65',
              },
              {
                name: '关闭温度报警',
                value: '66',
              },
              {
                name: '设置温度报警时长',
                value: '67',
                gets: [
                  {
                    name: '报警时长',
                    zd: 'xt',
                    placeholder: '请输入时间（秒）',
                    defaultValue: '',
                    dw: '秒',
                    rule: [
                      {
                        pattern: /^([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-6])$/,
                        message: '请输入(最大值为256)',
                      },
                    ],
                  },
                ],
              },
              {
                name: '重启分布式分机',
                value: '68',
                gets: [
                  {
                    name: '分机ID',
                    zd: 'newgtel',
                    placeholder: '分机ID',
                    defaultValue: '',
                  },
                ],
              },
              {
                name: '打开老的三位刷卡',
                value: '62',
              },
              {
                name: '用新的四位源码刷卡',
                value: '63',
              },
              {
                name: '道闸操作',
                value: '83',
                if: 'gtype',
                zhi: ['52', 52],
                gets: [
                  {
                    name: '操作类型',
                    zd: 'xt',
                    placeholder:
                      '0-关闭道闸，1-打开道闸，2-重启,3-道闸状态查询',
                    rule: [
                      {
                        required: true,
                        message: '请输入操作类型',
                        trigger: 'blur',
                      },
                    ],
                  },
                ],
              },
            ],
          },
        ],
        ChargeAskaddjson: [
          {
            name: '桩号',
            zd: 'gtel',
            rule: [{ required: true, message: '请输入桩号', trigger: 'blur' }],
          },
          {
            name: '设置类型',
            zd: 'lx',
            type: 'select',
            rule: [{ required: true, message: '请选择', trigger: 'blur' }],
            options: [
              {
                name: '开始充电',
                value: '1',
                gets: [
                  {
                    name: '通道',
                    zd: 'td',
                    rule: [
                      {
                        required: true,
                        message: '请输入通道号',
                        trigger: 'blur',
                      },
                    ],
                  },
                  {
                    name: '充电模式',
                    zd: 'xt',
                    type: 'select',
                    options: [
                      {
                        name: '时间模式',
                        value: '0',
                      },
                      {
                        name: '计量模式',
                        value: '1',
                      },
                    ],
                    defaultValue: '0',
                  },
                  {
                    name: '充电时长',
                    zd: 'cdsj',
                    if: 'xt',
                    zhi: ['0'],
                    defaultValue: '0',
                  },
                  {
                    name: '充电金额',
                    zd: 'cdsj',
                    if: 'xt',
                    zhi: ['1'],
                    dw: '元',
                    fl: '100',
                    rule: [
                      {
                        required: true,
                        message: '请输入充电金额',
                        trigger: 'blur',
                      },
                      { pattern: this.$z.test.amount(), message: '金额错误' },
                    ],
                  },
                ],
              },
              {
                name: '结束充电',
                value: '2',
                gets: [{ name: '通道', zd: 'td' }],
              },
              {
                name: '直通模式打开或者关闭',
                value: '3',
                gets: [
                  { name: '通道', zd: 'td' },
                  {
                    name: '直通模式',
                    zd: 'xt',
                    type: 'select',
                    options: [
                      {
                        name: '关闭',
                        value: '0',
                      },
                      {
                        name: '打开',
                        value: '1',
                      },
                    ],
                    defaultValue: '0',
                  },
                ],
              },
              {
                name: '重新设置用户充电剩余时长',
                value: '4',
                gets: [
                  { name: '通道', zd: 'td' },
                  {
                    name: '充电模式',
                    zd: 'xt',
                    type: 'select',
                    options: [
                      {
                        name: '时间模式',
                        value: '0',
                      },
                      {
                        name: '计量模式',
                        value: '1',
                      },
                    ],
                    defaultValue: '0',
                  },
                  { name: '充电时长', zd: 'cdsj', if: 'xt', zhi: ['0'] },
                  {
                    name: '充电金额',
                    zd: 'port',
                    if: 'xt',
                    zhi: ['1'],
                    dw: '元',
                    fl: '100',
                    rule: [
                      {
                        required: true,
                        message: '请输入充电金额',
                        trigger: 'blur',
                      },
                      { pattern: this.$z.test.amount(), message: '金额错误' },
                    ],
                  },
                ],
              },
              {
                name: '设置新的设备序列号',
                value: '6',
                gets: [
                  { name: '设备桩号', zd: 'newgtel' },
                  { name: '验证码', zd: 'yzm', type: 'utel' },
                ],
              },
              {
                name: '设置设备IP和端口',
                value: '7',
                gets: [
                  {
                    name: '服务器IP',
                    zd: 'ip',
                    bindingzd: { attr: 'chargecfg', zd: 'ip' },
                  },
                  {
                    name: '服务器端口',
                    zd: 'port',
                    bindingzd: { attr: 'chargecfg', zd: 'port' },
                  },
                ],
              },
              {
                name: '设备远程升级',
                value: '8',
              },
              {
                name: '设置浮充时间',
                value: '10',
                gets: [
                  {
                    name: '浮充时间',
                    zd: 'xt',
                    dw: '分钟',
                    // defaultValue: '80',
                    bindingzd: { attr: 'chargecfg', zd: 'jlsj' },
                  },
                ],
                if: () => {
                  return !this.ifqcrjbb23()
                },
              },
              {
                name: '汽车桩占空比',
                value: '10',
                gets: [
                  {
                    name: '占空比',
                    zd: 'xt',
                    defaultValue: '50',
                    bindingzd: { attr: 'chargecfg', zd: 'jlsj' },
                    rule: [
                      {
                        type: 'string',
                        required: true,

                        validator: (rule, value, callback) => {
                          value = Number(value)
                          if (value >= 27 && value <= 53) {
                            callback()
                          } else {
                            callback(`占空比应在27到53之间`)
                          }
                        },
                      },
                    ],
                  },
                ],
                if: () => {
                  return this.ifqcrjbb23()
                },
              },
              {
                name: '充电口功率最大值',
                value: '11',
                gets: [
                  {
                    name: '充电口功率最大值',
                    zd: 'xt',
                    dw: '瓦',
                    defaultValue: '800',
                    bindingzd: { attr: 'chargecfg', zd: 'maxdl' },
                  },
                ],
                if: () => {
                  return !this.ifqcrjbb23()
                },
              },
              {
                name: '汽车CP方式切换次数',
                value: '11',
                gets: [
                  {
                    name: '切换次数',
                    zd: 'xt',
                    defaultValue: '3',
                    bindingzd: { attr: 'chargecfg', zd: 'maxdl' },
                    rule: [
                      {
                        type: 'string',
                        required: true,

                        validator: (rule, value, callback) => {
                          value = Number(value)
                          if (value >= 3 && value <= 100) {
                            callback()
                          } else {
                            callback(`切换次数应在3到100之间`)
                          }
                        },
                      },
                    ],
                  },
                ],
                if: () => {
                  return this.ifqcrjbb23()
                },
              },
              {
                name: '重启设备',
                value: '12',
              },
              {
                name: '设备模式',
                value: '13',
                gets: [
                  {
                    name: '设备模式',
                    zd: 'xt',
                    type: 'select',
                    options: [
                      {
                        name: '免费',
                        value: '0',
                      },
                      {
                        name: '收费',
                        value: '1',
                      },
                    ],
                    defaultValue: '1',
                  },
                ],
              },
              {
                name: '打开烟雾报警检测',
                value: '16',
              },
              {
                name: '关闭烟雾报警检测',
                value: '17',
              },
              {
                name: '投币箱1元充电时间设置和是否启用',
                value: '23',
                gets: [
                  {
                    name: '投币是否启用',
                    zd: 'port',
                    type: 'select',
                    options: [
                      {
                        name: '不启用',
                        value: '0',
                      },
                      {
                        name: '启用',
                        value: '1',
                      },
                    ],
                    defaultValue: '0',
                    bindingzd: { attr: 'chargecfg', zd: 'b_tb' },
                  },
                  {
                    name: '1元充电时间设置',
                    zd: 'xt',
                    dw: '分钟',
                    defaultValue: '240',
                    bindingzd: { attr: 'chargecfg', zd: 'tbsj' },
                  },
                ],
              },
              {
                name: '设置断电检测时间',
                value: '26',
                gets: [
                  {
                    name: '断电检测时间',
                    zd: 'xt',
                    placeholder: '请输入（秒）',
                    defaultValue: '30',
                    dw: '秒',
                  },
                ],
              },
              {
                name: '设置设备音量',
                value: '27',
                gets: [
                  {
                    name: '音量大小',
                    zd: 'xt',
                    placeholder: '音量大小：0-15',
                    defaultValue: '3',

                    bindingzd: { attr: 'chargecfg', zd: 'b_yy' },
                    rule: [
                      {
                        pattern: /^([0-9]|1[0-5])$/,
                        message: '音量大小：0-15',
                      },
                    ],
                  },
                ],
              },
              {
                name: 'IC卡充值',
                value: '28',
                gets: [
                  {
                    name: '充值金额',
                    zd: 'xt',
                    dw: '元',
                    fl: 100,
                    rule: [
                      {
                        required: true,
                        message: '请输入充电金额',
                        trigger: 'blur',
                      },
                      { pattern: this.$z.test.amount(), message: '金额错误' },
                    ],
                  },
                ],
              },
              {
                name: '设置设备刷卡区域',
                value: '29',
              },
              {
                name: '设备温度报警值',
                if: 'gtype',
                nozhi: qcgtypes,
                value: '31',
                gets: [{ name: '温度报警值', zd: 'xt', dw: '度' }],
              },
              {
                name: '风扇最高温度',
                value: '31',
                if: 'gtype',
                zhi: qcgtypes,
                gets: [
                  {
                    name: '最低温度阈值',
                    zd: 'xt',
                    defaultValue: '75',
                    dw: '度',
                  },
                ],
              },
              {
                name: '电缆温度报警值',
                value: '32',
                if: 'gtype',
                nozhi: qcgtypes,
                gets: [
                  {
                    name: '温度报警值',
                    zd: 'xt',
                    defaultValue: '75',
                    dw: '度',
                    bindingzd: { attr: 'chargecfg', zd: 'wdxlal' },
                  },
                ],
              },
              {
                name: '断开充电温度值',
                value: '32',
                if: 'gtype',
                zhi: ['2'],
                gets: [
                  {
                    name: '最低温度阈值',
                    zd: 'xt',
                    defaultValue: '75',
                    dw: '度',
                    bindingzd: { attr: 'chargecfg', zd: 'wdxlal' },
                  },
                ],
              },
              {
                name: '风扇最低温度',
                value: '32',
                if: 'gtype',
                zhi: ['10'],
                gets: [
                  {
                    name: '最低温度阈值',
                    zd: 'xt',
                    defaultValue: '75',
                    dw: '度',
                    bindingzd: { attr: 'chargecfg', zd: 'wdxlal' },
                  },
                ],
              },
              {
                name: '设置涓流功率值',
                value: '33',
                if: 'gtype',
                nozhi: ['2'],
                gets: [
                  {
                    name: '涓流功率值',
                    zd: 'xt',
                    defaultValue: '10',
                    dw: '瓦',
                    bindingzd: { attr: 'chargecfg', zd: 'jldl' },
                  },
                ],
              },
              {
                name: '设置恢复充电温度值',
                value: '33',
                if: 'gtype',
                zhi: ['2'],
                gets: [
                  {
                    name: '恢复充电温度值',
                    zd: 'xt',
                    defaultValue: '10',
                    dw: '℃',
                    bindingzd: { attr: 'chargecfg', zd: 'jldl' },
                  },
                ],
              },
              {
                name: '设置断开功率值',
                value: '34',
                gets: [
                  {
                    name: '断开功率值',
                    zd: 'xt',
                    defaultValue: '2',
                    dw: '瓦',
                    bindingzd: { attr: 'chargecfg', zd: 'dkdl' },
                  },
                ],
              },
              {
                name: '最大充电时长',
                value: '35',
                gets: [
                  {
                    name: '最大充电时长',
                    zd: 'xt',
                    dw: '分钟',
                  },
                ],
              },
              {
                name: '开面板灯',
                value: '36',
              },
              {
                name: '关面板灯',
                value: '37',
              },
              {
                name: '打开插拔断电',
                value: '38',
                if: 'gtype',
                nozhi: qcgtypes,
              },
              {
                name: '关闭插拔断电',
                value: '39',
                if: 'gtype',
                nozhi: qcgtypes,
              },
              {
                name: '打开防倾倒',
                value: '38',
                if: 'gtype',
                zhi: qcgtypes,
              },
              {
                name: '关闭防倾倒',
                value: '39',
                if: 'gtype',
                zhi: qcgtypes,
              },
              {
                name: '触摸副板远程升级',
                value: '41',
              },
              {
                name: '打开充电口过流检测',
                value: '43',
              },
              {
                name: '关闭充电口过流检测',
                value: '44',
              },
              {
                name: '打开第二报警服务器',
                value: '46',
              },
              {
                name: '关闭第二报警服务器',
                value: '47',
              },
              {
                name: '查询系统参数',
                value: '52',
              },

              {
                name: '打开充满自停',
                value: '55',
                if: 'gtype',
                nozhi: qcgtypes,
              },
              {
                name: '关闭充满自停',
                value: '56',
                if: 'gtype',
                nozhi: qcgtypes,
              },
              {
                name: '打开设备指示灯',
                value: '55',
                if: 'gtype',
                zhi: qcgtypes,
              },
              {
                name: '关闭设备指示灯',
                value: '56',
                if: 'gtype',
                zhi: qcgtypes,
              },
              {
                name: '设置设备全卡通卡号',
                value: '57',
                gets: [
                  {
                    name: '印刷卡号',
                    zd: 'newgtel',
                    bindingzd: { attr: 'chargecfg', zd: 'cardid' },
                  },
                ],
              },
              {
                name: '清除硬件投币信息',
                value: '61',
              },
              {
                name: '打开条形支付',
                value: '62',
              },
              {
                name: '关闭条形码支付',
                value: '63',
              },
              {
                name: '获取充电柜温度',
                value: '65',
              },
              {
                name: '强制模块化',
                value: '71',
              },
              {
                name: '取消强制模块化',
                value: '72',
              },
              {
                name: '设置灯开关时间',
                value: '58',
                gets: [
                  {
                    name: '开始时间',
                    zd: 'lx58time1',
                    type: 'lx58time',
                    rule: [
                      { required: true, message: '开始时间', trigger: 'blur' },
                    ],
                  },
                  {
                    name: '结束时间',
                    zd: 'lx58time2',
                    type: 'lx58time',
                    rule: [
                      { required: true, message: '结束时间', trigger: 'blur' },
                    ],
                  },
                ],
              },
              {
                name: '副板升级',
                value: '76',
              },
              {
                name: '系统采用老版3位10进制码刷卡',
                value: '77',
              },
              {
                name: '系统采用新版4位源码刷卡',
                value: '78',
              },
              {
                name: '打开柜门',
                value: '80',
                gets: [{ name: '通道', zd: 'td' }],
              },
              {
                name: '设置打开继电器未检测到功率的时间',
                value: '82',
                gets: [
                  {
                    name: '未检测到功率的时间',
                    zd: 'xt',
                    // defaultValue: '10',
                    dw: '分',
                  },
                ],
              },
              {
                name: '道闸操作',
                value: '83',
                if: 'gtype',
                zhi: ['52', 52],
                gets: [
                  {
                    name: '操作类型',
                    zd: 'xt',
                    placeholder:
                      '0-关闭道闸，1-打开道闸，2-重启,3-道闸状态查询',
                    rule: [
                      {
                        required: true,
                        message: '请输入操作类型',
                        trigger: 'blur',
                      },
                    ],
                  },
                ],
              },

              {
                name: '自定义语音',
                value: '84',
                gets: [
                  {
                    name: '语音内容',
                    zd: 'newgtel',
                    placeholder: '传入语音内容',
                    rule: [
                      {
                        required: true,
                        message: '请输入语音内容',
                        trigger: 'blur',
                      },
                      {
                        required: true,
                        max: 16,
                        message: '语音字符超长',
                        trigger: 'change',
                      },
                    ],
                  },
                  {
                    name: '语音位置',
                    zd: 'xt',
                    placeholder: '传入语音位置',
                    type: 'select',
                    options: [
                      {
                        name: '立刻播放',
                        value: '0',
                      },
                      {
                        name: '系统启动中',
                        value: '1',
                      },
                      {
                        name: '系统启动完毕',
                        value: '2',
                      },
                      {
                        name: '开始充电',
                        value: '3',
                      },
                      {
                        name: '结束充电',
                        value: '4',
                      },
                    ],
                    rule: [
                      {
                        required: true,
                        message: '请选择语音位置',
                        trigger: 'blur',
                      },
                    ],
                  },
                ],
              },
            ],
          },
        ],
        ChargeSetYKCaddjson: [
          {
            name: '桩号',
            zd: 'gtel',
            rule: [{ required: true, message: '请输入桩号', trigger: 'blur' }],
          },
          {
            name: '设置类型',
            zd: 'lx',
            type: 'select',
            rule: [{ required: true, message: '请选择', trigger: 'blur' }],
            options: [
              // 1-开，2-关，3-重启，4-计费模式下发，7-设置二维码，8-地锁控制
              {
                name: '开启通道',
                value: '1',
                gets: [
                  {
                    name: '通道',
                    zd: 'td',
                    defaultValue: '',
                    rule: [
                      {
                        required: true,
                        message: '请输入通道',
                        trigger: 'blur',
                      },
                    ],
                  },
                ],
              },
              {
                name: '关闭通道',
                value: '2',
                gets: [
                  {
                    name: '通道',
                    zd: 'td',
                    defaultValue: '',
                    rule: [
                      {
                        required: true,
                        message: '请输入通道',
                        trigger: 'blur',
                      },
                    ],
                  },
                ],
              },
              {
                name: '重启设备',
                value: '3',
              },
              {
                name: '计费模式下发',
                value: '4',
              },

              {
                name: '升级程序',
                value: '6',
                gets: [
                  {
                    name: '程序类型',
                    zd: 'td',
                    defaultValue: '',
                    type: 'select',
                    options: [
                      { value: '0', name: '公司自己的程序' },
                      { name: '易电7寸屏', value: '1' },
                      { name: '易电4.3寸屏', value: '2' },
                      { name: '双枪', value: '3' },
                      { name: '易电直流桩', value: '4' },
                      { name: '不带二维码', value: '5' },
                    ],
                    // defaultValue: '0',
                    rule: [
                      {
                        required: true,
                        message: '请选择程序类型',
                        trigger: 'blur',
                      },
                    ],
                  },
                ],
              },
              {
                name: '设置二维码',
                value: '7',
              },
              {
                name: '地锁控制',
                value: '8',

                gets: [
                  {
                    name: '操作类型',
                    zd: 'df',
                    type: 'select',
                    options: [
                      {
                        name: '地锁下降',
                        value: '0',
                      },
                      {
                        name: '地锁上升',
                        value: '1',
                      },
                    ],
                    defaultValue: '0',
                    rule: [
                      {
                        required: true,
                        message: '请输入操作类型',
                        trigger: 'blur',
                      },
                    ],
                  },
                ],
              },

              {
                name: '声音控制',
                value: '9',

                gets: [
                  {
                    name: '声音控制',
                    zd: 'df',
                    placeholder: '范围0-15，0为关闭声音',
                    defaultValue: '',
                    rule: [
                      {
                        required: true,
                        message: '请输入内容',
                        trigger: 'blur',
                      },
                    ],
                  },
                ],
              },
            ],
          },
        ],
        ChargeSetYKCaddgtype20json: [
          {
            name: '桩号',
            zd: 'gtel',
            rule: [{ required: true, message: '请输入桩号', trigger: 'blur' }],
          },
          {
            name: '设置类型',
            zd: 'lx',
            type: 'select',
            rule: [{ required: true, message: '请选择', trigger: 'blur' }],
            defaultValue: '8',
            options: [
              {
                name: '地锁控制',
                value: '8',

                gets: [
                  {
                    name: '通道',
                    zd: 'td',
                    defaultValue: '',
                    rule: [
                      {
                        required: true,
                        message: '请输入通道',
                        trigger: 'blur',
                      },
                    ],
                  },
                  {
                    name: '操作类型',
                    zd: 'df',
                    type: 'select',
                    options: [
                      {
                        name: '地锁下降',
                        value: '1',
                      },
                      {
                        name: '地锁上升',
                        value: '0',
                      },
                    ],
                    defaultValue: '0',
                    rule: [
                      {
                        required: true,
                        message: '请输入操作类型',
                        trigger: 'blur',
                      },
                    ],
                  },
                ],
              },
              {
                name: '升级程序',
                value: '6',
                gets: [
                  {
                    name: '程序类型',
                    zd: 'td',
                    defaultValue: '',
                    type: 'select',
                    options: [{ value: '0', name: '公司自己的程序' }],
                    defaultValue: '0',
                    rule: [
                      {
                        required: true,
                        message: '请选择程序类型',
                        trigger: 'blur',
                      },
                    ],
                  },
                ],
              },
            ],
          },
        ],
        qrcodedata: { gtel: '', gls: 0 },
        zjsbarcodegtels: [],
        getChargeCardata: {},
      }
    },
    computed: {
      frominputs: {
        get: function () {
          let dqjson =
              this.getChargeCardata.b_ask == 1
                ? this.ChargeAskaddjson
                : this.ChargeSetaddjson,
            r = []
          if (this.getChargeCardata.gtype == '62') {
            dqjson = this.ChargeSetYKCaddjson
          } else if (this.getChargeCardata.gtype == '20') {
            dqjson = this.ChargeSetYKCaddgtype20json
          }
          //
          dqjson.forEach((e) => {
            if (e.type == 'select') {
              let p = { ...e, label: e.name, value: e.zd, type: 'select' }
              let option = e.options.map((m) => {
                return { ...m, label: m.name, value: m.value }
              })
              p.option = option
              r.push(p)
              e.options.forEach((optione) => {
                let gets = optione.gets ? optione.gets : []
                gets.forEach((fe) => {
                  let addattr = {}
                  let judge = []
                  if (fe.if) {
                    judge.push({ value: fe.if, zhi: fe.zhi })
                  }
                  if (typeof optione.if == 'function') {
                    judge.push(optione.if)
                  } else if (optione.if) {
                    judge.push({
                      value: optione.if,
                      zhi: optione.zhi,
                      nozhi: optione.nozhi ? optione.nozhi : [],
                    })
                  }
                  judge.push({ value: e.zd, zhi: [optione.value] })

                  addattr.if = judge

                  if (fe.type == 'select') {
                    addattr.option = fe.options.map((mp) => {
                      return { label: mp.name, value: mp.value }
                    })
                  }
                  r.push({ ...fe, label: fe.name, value: fe.zd, ...addattr })
                })
              })
            } else {
              r.push({ ...e, label: e.name, value: e.zd })
            }
          })
          // let typejson=dqjson[1].options
          return r
        },
        set: function () {
          // settingfn
        },
      },
    },
    watch: {
      // :ChargeCfg="ChargeCfg" :nowinputs="frominputs"
      // :nowdata="formdata"

      gtel: function (gtel) {
        this.formdata.gtel = gtel
        this.ChargeCarfn(gtel)
      },
      // ChargeCardata:{
      //   deep:true, //深度监听设置为 true
      //   handler:function(n,o) {
      //     console.log(n,o)
      //   }
      // },
      ChargeCardata: function (n, o) {
        if (n.gtel != o.gtel && n.gtel != '') {
          this.ChargeCarfn(n.gtel)
        }
      },
    },
    mounted() {},
    methods: {
      excelfn() {
        this.$refs.exceladd.show()
      },
      ifqcrjbb23() {
        let gtype = ['2', '10'].findIndex((e) => {
          return e == this.chargecardata.gtype
        })
        if (gtype == -1) {
          return false
        }
        return Number(this.chargecardata.rjbb) >= 23
      },
      excelsave(gtels) {
        let gtelsstr = gtels
          .map((e) => {
            return e.gtel
          })
          .join(';')
        this.formdata.gtel = gtelsstr
        this.gtelblurfn()
      },
      async qrfn() {
        this.getgtelfn().then(async (gtels) => {
          let gtel = gtels.split(';')
          this.ewmsdownload(gtel)
        })
      },
      txmfn() {
        //
        this.getgtelfn().then(async (gtels) => {
          let gtel = gtels.split(';')
          this.zjsbarcodegtels = gtel.filter((e) => {
            return e != ''
          })
          setTimeout(() => {
            this.$z
              .zhtml2canvas(
                this.$refs.refzjsbarcode,
                '云享充电' + this.$z.randomString(5)
              )
              .then(() => {
                let hnum = Math.ceil(this.zjsbarcodegtels.length / 3) * 12
                this.$notify({
                  title: '提示',
                  duration: 0,
                  message: h(
                    'div',
                    { style: 'color: #2093f5' },
                    `打印机标准94*${hnum}`
                  ),
                })
              })
          }, 300)
        })
      },
      csdataalookfn() {
        this.getgtelfn().then(async (gtels) => {
          this.$notify({
            title: '搜索结果',
            duration: 0,
            message: h('div', { style: 'color: #606266' }, gtels),
          })
        })
      },
      ewmsdownload(gtels, i = 0, qrcodedata) {
        this.ewmloading = true
        if (gtels.length - 1 < i) {
          this.ewmloading = false
          return
        }
        let gtel = gtels[i]
        if (gtel == '') {
          i++
          this.ewmsdownload(gtels, i)
          return
        }
        let ls = this.ChargeCardata.gls ? this.ChargeCardata.gls : 10
        this.qrcodedata = qrcodedata
          ? qrcodedata
          : { gtel: gtel, gls: ls, glsi: 0 }
        setTimeout(() => {
          let mc = '云享充电' + gtel
          if (ls > 10) {
            mc += `(${this.qrcodedata.glsi}_${this.qrcodedata.glsi + 10})`
          }
          this.$z.zhtml2canvas(this.$refs.vueqrcode, mc).then(() => {
            if (this.qrcodedata.glsi + 10 < ls) {
              this.qrcodedata.glsi += 10
              this.ewmsdownload(gtels, i, this.qrcodedata)
            } else {
              i++
              this.ewmsdownload(gtels, i)
            }
          })
        }, 1000)
      },
      async gteljc() {
        let gtels = await this.getgtelfn()
        gtels = gtels.split(';')
        let reqdata = {}
        reqdata.gtelsum = gtels.length
        gtels.forEach((e, i) => {
          reqdata[`gtel${i + 1}`] = e
        })
        let ChargeCarCD = await this.$z.$axios.post('/ChargeCarCD', reqdata)
        ChargeCarCD = ChargeCarCD.data
        let datab_ask1 = ChargeCarCD.filter((e) => {
          return e.b_ask == 1
        }).map((e) => {
          return e.gtel
        })
        if (datab_ask1.length == 0 || datab_ask1.length == ChargeCarCD.length) {
          this.$message.success('正确')
          return
        }
        let datab_ask0 = ChargeCarCD.filter((e) => {
          return e.b_ask == 0
        }).map((e) => {
          return e.gtel
        })

        this.$notify({
          title: '应答协议设备',
          duration: 0,
          message: h('div', { style: 'color: #606266' }, datab_ask1.join(';')),
        })
        this.$notify({
          title: '非应答协议设备',
          duration: 0,
          message: h('div', { style: 'color: #606266' }, datab_ask0.join(';')),
        })
      },
      async gtelblurfn() {
        this.getgtelfn().then(async (gtels) => {
          let gtel = gtels.split(';')
          gtel = gtel[0]

          // this.formdata = {gtel: gtels};
          let ChargeCardata = await this.$z.$axios.post('/ChargeCar', {
            gtel: gtel,
          })
          let { data } = ChargeCardata

          if (data.length == 1) {
            // if (
            //   data[0].b_ask != this.getChargeCardata.b_ask ||
            //   data[0].gtype != this.getChargeCardata.gtype ||
            //   data[0].rjbb != this.getChargeCardata.rjbb
            // ) {

            // }
            this.getChargeCardata = data[0]
            this.$emit('setChargeCardatafn', data[0], gtels)
          }
        })
      },
      async ChargeCarfn(gtel) {
        if (!gtel) {
          return
        }
        this.formdata = { gtel: this.gtel }
        let ChargeCardata = await this.$z.$axios.post('/ChargeCar', {
          gtel: gtel,
        })
        let { data } = ChargeCardata
        if (data.length == 1) {
          if (data[0].b_ask != this.getChargeCardata.b_ask) {
            this.getChargeCardata = data[0]
          }
          this.formdata = { gtype: String(data[0].gtype), ...this.formdata }
        }
        let ChargeCfg = await this.$z.$axios.post('/ChargeCfg', { gtel: gtel })
        ChargeCfg = ChargeCfg.data

        this.ChargeCfg = ChargeCfg.length == 1 ? ChargeCfg[0] : {}
      },
      setdatainputfn() {
        let formdata = { ...this.formdata },
          frominputs = []
        formdata.gtel = this.gtel

        this.formdata = formdata
        this.frominputs = frominputs
      },
      Promiseallfn(data) {
        return new Promise((resolve) => {
          if (
            data.lx == '6' &&
            this.getChargeCardata.gtype != 62 &&
            this.getChargeCardata.gtype != 20
          ) {
            data = { ...data, newgtel: data.gtel, gtel: data.newgtel }
          }
          let url =
            this.getChargeCardata.b_ask == 1 ? '/ChargeAskadd' : '/ChargeSetadd'
          if (
            this.getChargeCardata.gtype == 62 ||
            this.getChargeCardata.gtype == 20
          ) {
            url = '/ChargeSetYKCadd'
          }
          if (url == '/ChargeAskadd' && data.lx == '58') {
            let str1 = data.lx58time1.split(':')
            data.td = parseInt(str1[0])
            data.cdsj = parseInt(str1[1])
            let str2 = data.lx58time2.split(':')
            data.port = parseInt(str2[0])
            data.xt = Number(str2[1])
          }
          if (url == '/ChargeAskadd' && data.lx == '29') {
            data.xt = this.getChargeCardata.pcs
          }
          if (url == '/ChargeAskadd' && (data.lx == '1') & (data.cdsj == '')) {
            data.cdsj = 0
          }
          this.$z.$axios.post(url, data).then(async (reqdata) => {
            resolve(reqdata.data)
          })
        })
      },
      ChargeSetaddfn() {
        this.$refs.zfrom.validate().then((data) => {
          let upgtels = data.gtel.split(';'),
            Promisealls = []
          upgtels.forEach((e) => {
            if (e != '') {
              Promisealls.push(this.Promiseallfn({ ...data, gtel: e }))
            }
          })
          Promise.all(Promisealls).then(async (datas) => {
            let data = datas[0],
              par = parfn(data)
            if (par.value == 'succeed') {
              let ChargeCfg = await this.$z.$axios.post('/ChargeCfg', {
                gtel: upgtels[0],
              })
              ChargeCfg = ChargeCfg.data
              this.ChargeCfg = ChargeCfg.length == 1 ? ChargeCfg[0] : {}

              this.$emit('ChargeSetadd', upgtels[0])

              this.$message.success(par.label)
            } else {
              this.$message.error(par.label)
            }
          })
        })
      },
      getChargeaddjsonfn() {
        let optionjson = this.$z.deepClone(this.frominputs[1].options)

        optionjson = optionjson.filter((f) => {
          if (f['if']) {
            if (typeof f['if'] == 'object') {
              let r = f['if'].find((fif) => {
                if (fif.value == 'lx') {
                  return false
                }
                if (typeof fif == 'function') {
                  let ifdata = fif()
                  if (!ifdata) {
                    return true
                  }
                }
                let zhi = this.formdata[fif['value']]
                  ? this.formdata[fif['value']]
                  : ''
                fif['zhi'] = fif['zhi'] ? fif['zhi'] : []
                fif['nozhi'] = fif['nozhi'] ? fif['nozhi'] : []
                let nozhifalg =
                  fif['nozhi'].indexOf(this.formdata[fif['value']]) >= 0
                if (nozhifalg) {
                  return true
                } else if (fif['zhi'].length == 0) {
                  return false
                }
                return fif['zhi'].indexOf(zhi) < 0
              })
              return !r
            } else if (typeof f['if'] == 'string') {
              f['zhi'] = f['zhi'] ? f['zhi'] : ''
              return f['zhi'].indexOf(this.formdata[f['if']]) >= 0
            } else if (typeof f.if == 'function') {
              return f.if()
            } else {
              return true
            }
          } else {
            return true
          }
        })
        console.log(optionjson, 'optionjson')
        return optionjson
      },
      async getgtelfn() {
        return await this.$refs.zfrom.validateField('gtel').then((data) => {
          if (typeof data == 'undefined') {
            return ''
          }
          return data
        })
      },
    },
  }
</script>
<style scoped></style>
